﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MTC.Common;
using MTC.Web.Business;

namespace MTC.Web.Master
{
    public partial class Detail : System.Web.UI.MasterPage
    {
        public Session AppVars { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        override protected void OnInit(EventArgs e)
        {
            base.OnInit(e);


            //It appears from testing that the Request and Response both share the 
            // same cookie collection.  If I set a cookie myself in the Reponse, it is 
            // also immediately visible to the Request collection.  This just means that 
            // since the ASP.Net_SessionID is set in the Session HTTPModule (which 
            // has already run), thatwe can't use our own code to see if the cookie was 
            // actually sent by the agent with the request using the collection. Check if 
            // the given page supports session or not (this tested as reliable indicator 
            // if EnableSessionState is true), should not care about a page that does 
            // not need session
            if (Context.Session != null)
            {
                //Tested and the IsNewSession is more advanced then simply checking if 
                // a cookie is present, it does take into account a session timeout, because 
                // I tested a timeout and it did show as a new session
                AppVars = (Session)Session[Globals.SESSION_FIELDS];
                if (AppVars == null)
                    Response.Redirect(Globals.LoginScreen);

            }
        }

        protected void lnkLogout_Click(object sender, EventArgs e)
        {
            Session[Globals.SESSION_FIELDS] = null;
            Response.Redirect(Globals.LoginScreen);
        }

    }
}
